package com.bingxue.edu.management.report.controller;

import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.framework.security.ApiResource;
import com.bingxue.edu.management.education.model.entity.ClassStat;
import com.bingxue.edu.management.education.model.query.ClassQuery;
import com.bingxue.edu.management.education.service.ClassStatService;
import com.bingxue.edu.management.report.model.resp.ClassStatResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author panbo
 * @since 2024/11/26
 */
@Slf4j
@Tag(name = "数据统计接口")
@RestController
@RequestMapping("/report/class")
@RequiredArgsConstructor
public class ClassStatReportController {

    private final ClassStatService classStatService;

    @Operation(summary = "批量查询班级统计数据")
    @ApiResource("report:class:stat")
    @GetMapping("/stat")
    public Response<List<ClassStatResp>> getClassStatList(ClassQuery query) {
        return Response.success(classStatService.getClassStatList(query));
    }

    @Operation(summary = "查询单个班级统计数据")
    @ApiResource("report:class:stat")
    @GetMapping("/stat/{classId}")
    public Response<ClassStat> getClassStat(@PathVariable String classId) {
        return Response.success(classStatService.getClassStatById(classId));
    }

//
//    @Operation(summary = "班级续报信息表格导出" , description = "班级续报信息表格导出")
//    @ApiResource("report:class:stat")
//    @GetMapping("/class/stat-export/")
//    public Response<Void> exportSingleClassContinueStats(HttpServletResponse response, @PathVariable String classId) throws IOException {
//
//        List<ClassContinueExportModel> resultList = statsService.getClassContinueExportModelByClassId(classId);
//
//        if (resultList.isEmpty()) {
//            throw new BusinessException("学生列表为空，导出失败");
//        }
//
//        // 设置响应头，告诉浏览器这是一个文件下载
//        ClassInfo classInfo = classInfoService.getById(classId) ;
//        Employee employee = employeeService.getById(classInfo.getLeadTeacherId());
//        String className = classInfo.getName() + "-" + employee.getName();
//        String fileName = URLEncoder.encode("【续报明细】" + className + ".xlsx", "UTF-8");
//        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//        response.setCharacterEncoding("UTF-8");
//        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
//
//        // 使用 EasyExcel 导出
//        EasyExcel.write(response.getOutputStream(), ClassContinueExportModel.class)
//                .excelType(ExcelTypeEnum.XLSX)
//                .sheet("续报统计")
//                .doWrite(resultList);
//        return null;
//    }
//
//    @Operation(summary = "班级续报信息表格导出" , description = "班级续报信息表格导出")
//    @ApiResource("report:class:stat")
//    @GetMapping("/exportSingleClassCancelStats/{classId}")
//    public Response<Void> exportSingleClassCancelStats(HttpServletResponse response,@PathVariable String classId) throws IOException {
//        List<ClassCancelExportModel> resultList = statsService.getClassCancelExportModelByClassId(classId);
//
//        ClassInfo classInfo = classInfoService.getById(classId);
//        Employee employee = employeeService.getById(classInfo.getLeadTeacherId());
//        String className = classInfo.getName() + "-" + employee.getName();
//        String fileName = "【退课明细】" + className + ".xlsx";
//        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//        response.setCharacterEncoding("UTF-8");
//        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
//
//        EasyExcel.write(response.getOutputStream(), ClassCancelExportModel.class)
//                .excelType(ExcelTypeEnum.XLSX)
//                .sheet("退课统计")
//                .doWrite(resultList);
//
//        return null;
//    }
}


